import {observable, action, runInAction} from 'mobx';
import {Toast} from 'antd-mobile';

/**
 * mobx 状态管理类，所有的逻辑处理都在这里
 * */
class PropertyFeePayStore {
    @observable payType = 'wx_app'; //支付类型
    @observable payments = 0;//付款金额
    @observable actualPayments = 0;//实际付款金额
    @observable discount; //赠送折扣
    @observable discountType; //赠送类型
    @observable attach = '';
    @observable attach2 = '';
    @observable detail = '';

    @action
    componentDidMount = (props) => {
        runInAction(() => {
            this.payments = parseFloat(props.location.state.payments);
            this.actualPayments = parseFloat(props.location.state.payments);
            this.payType = 'wx_app';
            this.attach = props.location.state.id;
            this.detail = JSON.stringify({
                months: props.location.state.months,
                lastBillDate: props.location.state.lastBillDate,
                currentBillDate: props.location.state.currentBillDate
            });
        });
    };

    @action
    onChangePayType = (payType) => {
        runInAction(() => {
            this.payType = payType;
        });
    };

    paySubmit = (props) => {
        let params = {
            payType: "wx_h5",
            body: '物业缴费',
            orderType: "PROPERTY_FEE",
            totalFee: 0.01,
            payableFee: this.payments,
            ownerCode: ownerCode,
            commCode: commCode,
            attach: this.attach,
            attach2: this.attach2,
            detail: this.detail
        };
        postJson("/api/v2/pay/anon/weixin/H5/order", params, (data) => {
            Toast.loading('加载中...', 2);
            window.location.href = data.webUrl;
        }, (data) => {
            Toast.info(data.data ? data.data : data, 2, null, false);
        });
    };
}

export default new PropertyFeePayStore()